package com.chen.service.provider;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chen.dao.provider.ProviderDao;
import com.chen.pojo.Provider;
@Service("providerService")
public class ProviderServiceImpl implements ProviderService {
	@Autowired
	private ProviderDao providerDao;
	@Override
	public boolean add(Provider provider) throws Exception {
		return providerDao.add(provider) > 0;
	}

	@Override
	public List<Provider> getProviderList(String proName,String proCode,int currentPageNo, int pageSize) throws Exception {
		return providerDao.getProviderList(proName, proCode, (currentPageNo - 1)*pageSize, pageSize);
	}

	@Override
	public int deleteProviderById(String delId) {
		int billCount = -1;
		try {
			billCount = providerDao.deleteProviderById(delId);
			if(billCount == 0){
				providerDao.deleteProviderById( delId);
			}
		} catch (Exception e) {
			e.printStackTrace();
			billCount = -1;
		}
		return billCount;
	}

	@Override
	public Provider getProviderById(String id) throws Exception {
		return providerDao.getProviderById(id);
	}

	@Override
	public boolean modify(Provider provider) throws Exception {
		return providerDao.modify(provider) > 0;
	}
	@Override
	public int getProvierCount(String proName, String proCode) throws Exception {
		return providerDao.getProviderCount(proName, proCode);
	}

	@Override
	public List<Provider> queryList() throws SQLException {
		return providerDao.queryList();
	}

}
